using System;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;

namespace CANBusTools.ViewModels
{
    public class GearControlViewModel : ViewModelBase
    {
        private readonly object _busHelper;

        public string[] GearValues { get; } = new[] { "P", "R", "N", "D" };

        private string _selectedGear = "P";
        public string SelectedGear
        {
            get => _selectedGear;
            set
            {
                if (_selectedGear != value)
                {
                    _selectedGear = value;
                    OnPropertyChanged(nameof(SelectedGear));
                }
            }
        }

        public ICommand SetGearCommand { get; }

        public GearControlViewModel(object busHelper)
        {
            _busHelper = busHelper;
            SetGearCommand = new RelayCommand(SetGear);
        }

        private void SetGear()
        {
            // 这里调用 BusHelper 的 GearSwitch 方法，示例中暂时用占位逻辑
            // 档位映射
            var gearMap = new System.Collections.Generic.Dictionary<string, int>
            {
                { "P", 6 },
                { "R", 8 },
                { "N", 1 },
                { "D", 5 }
            };

            if (gearMap.TryGetValue(SelectedGear, out int gearValue))
            {
                // TODO: 替换为实际调用 _busHelper.GearSwitch(gearValue.ToString());
                Console.WriteLine($"Set gear to {SelectedGear} ({gearValue})");
            }
        }
    }
}
